package Basics;

public class 单列设计模式 {

}
//饿汉式单例

class A{
    private static A a = new A();
    private A(){

    }

    private static Object getObj(){
        return a;
    }
}
//懒汉式单例

class B{
    private static B b;
    private B(){

    }
    private static Object getObj(){
        if(b == null){
            b = new B();
        }
        return b;
    }
}